﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace YArchitech.Controls.ImgListView
{
	public static class ImageListViewRenderers
	{
		public class DefaultRenderer : ImageListView.ImageListViewRenderer
		{
		}

		public class NoirRenderer : ImageListView.ImageListViewRenderer
		{
			public int ReflectionSize
			{
				get
				{
					return this.mReflectionSize;
				}
				set
				{
					this.mReflectionSize = value;
				}
			}

			public NoirRenderer() : this(20)
			{
			}

			public NoirRenderer(int reflectionSize)
			{
				this.mReflectionSize = reflectionSize;
				this.padding = 4;
			}

			public override void DrawBackground(Graphics g, System.Drawing.Rectangle bounds)
			{
				g.Clear(System.Drawing.Color.FromArgb(16, 16, 16));
			}

			public override Size MeasureItem(Autodesk.Revit.DB.View view)
			{
				if (view == Autodesk.Revit.DB.View.Details)
				{
					return base.MeasureItem(view);
				}
				return new Size(base.ImageListView.ThumbnailSize.Width + 2 * this.padding, base.ImageListView.ThumbnailSize.Height + 2 * this.padding + this.mReflectionSize);
			}

			public override void DrawItem(Graphics g, ImageListViewItem item, ItemState state, System.Drawing.Rectangle bounds)
			{
				if (item.BackColor != System.Drawing.Color.Transparent)
				{
					using (Brush brush = new SolidBrush(item.BackColor))
					{
						g.FillRectangle(brush, bounds);
					}
				}
				if (base.ImageListView.View == Autodesk.Revit.DB.View.Details)
				{
					if ((state & ItemState.Selected) == ItemState.Selected)
					{
						using (Brush brush2 = new LinearGradientBrush(bounds, System.Drawing.Color.FromArgb(64, 96, 160), System.Drawing.Color.FromArgb(64, 64, 96, 160), LinearGradientMode.Horizontal))
						{
							g.FillRectangle(brush2, bounds);
							goto IL_C9;
						}
					}
					if ((state & ItemState.Hovered) == ItemState.Hovered)
					{
						using (Brush brush3 = new LinearGradientBrush(bounds, System.Drawing.Color.FromArgb(64, System.Drawing.Color.White), System.Drawing.Color.FromArgb(16, System.Drawing.Color.White), LinearGradientMode.Horizontal))
						{
							g.FillRectangle(brush3, bounds);
						}
					}
					IL_C9:
					List<ImageListView.ImageListViewColumnHeader> displayedColumns = this.mImageListView.Columns.GetDisplayedColumns();
					int num = this.mImageListView.layoutManager.ColumnHeaderBounds.Left;
					foreach (ImageListView.ImageListViewColumnHeader imageListViewColumnHeader in displayedColumns)
					{
						if (this.mImageListView.SortColumn == imageListViewColumnHeader.Type && this.mImageListView.SortOrder != SortOrder.None && (state & ItemState.Hovered) == ItemState.None && (state & ItemState.Selected) == ItemState.None)
						{
							System.Drawing.Rectangle rect = bounds;
							rect.X = num;
							rect.Width = imageListViewColumnHeader.Width;
							using (Brush brush4 = new SolidBrush(System.Drawing.Color.FromArgb(32, 128, 128, 128)))
							{
								g.FillRectangle(brush4, rect);
								break;
							}
						}
						num += imageListViewColumnHeader.Width;
					}
					num = this.mImageListView.layoutManager.ColumnHeaderBounds.Left;
					foreach (ImageListView.ImageListViewColumnHeader imageListViewColumnHeader2 in displayedColumns)
					{
						num += imageListViewColumnHeader2.Width;
						if (imageListViewColumnHeader2 != displayedColumns[displayedColumns.Count - 1])
						{
							using (Pen pen = new Pen(System.Drawing.Color.FromArgb(64, 128, 128, 128)))
							{
								g.DrawLine(pen, num, bounds.Top, num, bounds.Bottom);
							}
						}
					}
					Size size = new Size(2, (bounds.Height - this.mImageListView.Font.Height) / 2);
					using (StringFormat stringFormat = new StringFormat())
					{
						stringFormat.FormatFlags = StringFormatFlags.NoWrap;
						stringFormat.Alignment = StringAlignment.Near;
						stringFormat.LineAlignment = StringAlignment.Center;
						stringFormat.Trimming = StringTrimming.EllipsisCharacter;
						RectangleF layoutRectangle = new RectangleF((float)(bounds.Left + size.Width), (float)(bounds.Top + size.Height), (float)(displayedColumns[0].Width - 2 * size.Width), (float)(bounds.Height - 2 * size.Height));
						foreach (ImageListView.ImageListViewColumnHeader imageListViewColumnHeader3 in displayedColumns)
						{
							layoutRectangle.Width = (float)(imageListViewColumnHeader3.Width - 2 * size.Width);
							using (Brush brush5 = new SolidBrush(System.Drawing.Color.White))
							{
								g.DrawString(item.GetSubItemText(imageListViewColumnHeader3.Type), this.mImageListView.Font, brush5, layoutRectangle, stringFormat);
							}
							layoutRectangle.X += (float)imageListViewColumnHeader3.Width;
						}
					}
					if ((state & ItemState.Hovered) == ItemState.Hovered)
					{
						using (Pen pen2 = new Pen(System.Drawing.Color.FromArgb(128, System.Drawing.Color.White)))
						{
							g.DrawRectangle(pen2, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1);
							return;
						}
					}
					if ((state & ItemState.Selected) != ItemState.Hovered)
					{
						return;
					}
					using (Pen pen3 = new Pen(System.Drawing.Color.FromArgb(96, 144, 240)))
					{
						g.DrawRectangle(pen3, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1);
						return;
					}
				}
				Image thumbnailImage = item.ThumbnailImage;
				System.Drawing.Rectangle sizedImageBounds = Utility.GetSizedImageBounds(thumbnailImage, new System.Drawing.Rectangle(bounds.X + this.padding, bounds.Y + this.padding, bounds.Width - 2 * this.padding, bounds.Height - 2 * this.padding - this.mReflectionSize), 50f, 100f);
				int x = sizedImageBounds.X;
				int y = sizedImageBounds.Y;
				if ((state & ItemState.Selected) == ItemState.Selected)
				{
					using (Brush brush6 = new LinearGradientBrush(new System.Drawing.Point(x - this.padding, y - this.padding), new System.Drawing.Point(x - this.padding, y + sizedImageBounds.Height + 2 * this.padding), System.Drawing.Color.FromArgb(64, 96, 160), System.Drawing.Color.FromArgb(16, 16, 16)))
					{
						g.FillRectangle(brush6, x - this.padding, y - this.padding, sizedImageBounds.Width + 2 * this.padding, sizedImageBounds.Height + 2 * this.padding);
						goto IL_608;
					}
				}
				if ((state & ItemState.Hovered) == ItemState.Hovered)
				{
					using (Brush brush7 = new LinearGradientBrush(new System.Drawing.Point(x - this.padding, y - this.padding), new System.Drawing.Point(x - this.padding, y + sizedImageBounds.Height + 2 * this.padding), System.Drawing.Color.FromArgb(64, System.Drawing.Color.White), System.Drawing.Color.FromArgb(16, 16, 16)))
					{
						g.FillRectangle(brush7, x - this.padding, y - this.padding, sizedImageBounds.Width + 2 * this.padding, sizedImageBounds.Height + 2 * this.padding);
					}
				}
				IL_608:
				if ((state & ItemState.Hovered) == ItemState.Hovered)
				{
					using (Brush brush8 = new LinearGradientBrush(new System.Drawing.Point(x - this.padding, y - this.padding), new System.Drawing.Point(x - this.padding, y + sizedImageBounds.Height + 2 * this.padding), System.Drawing.Color.FromArgb(128, System.Drawing.Color.White), System.Drawing.Color.FromArgb(16, 16, 16)))
					{
						using (Pen pen4 = new Pen(brush8))
						{
							g.DrawRectangle(pen4, x - this.padding, y - this.padding + 1, sizedImageBounds.Width + 2 * this.padding - 1, sizedImageBounds.Height + 2 * this.padding - 1);
							goto IL_797;
						}
					}
				}
				if ((state & ItemState.Selected) == ItemState.Selected)
				{
					using (Brush brush9 = new LinearGradientBrush(new System.Drawing.Point(x - this.padding, y - this.padding), new System.Drawing.Point(x - this.padding, y + sizedImageBounds.Height + 2 * this.padding), System.Drawing.Color.FromArgb(96, 144, 240), System.Drawing.Color.FromArgb(16, 16, 16)))
					{
						using (Pen pen5 = new Pen(brush9))
						{
							g.DrawRectangle(pen5, x - this.padding, y - this.padding + 1, sizedImageBounds.Width + 2 * this.padding - 1, sizedImageBounds.Height + 2 * this.padding - 1);
						}
					}
				}
				IL_797:
				this.DrawImageWithReflection(g, thumbnailImage, sizedImageBounds, this.mReflectionSize);
				using (Pen pen6 = new Pen(System.Drawing.Color.FromArgb(160, System.Drawing.Color.White)))
				{
					g.DrawLine(pen6, sizedImageBounds.X, sizedImageBounds.Y + 1, sizedImageBounds.X + sizedImageBounds.Width - 1, sizedImageBounds.Y + 1);
					g.DrawLine(pen6, sizedImageBounds.X, sizedImageBounds.Y + 1, sizedImageBounds.X, sizedImageBounds.Y + sizedImageBounds.Height);
				}
			}

			public override void DrawColumnHeader(Graphics g, ImageListView.ImageListViewColumnHeader column, ColumnState state, System.Drawing.Rectangle bounds)
			{
				if (this.mImageListView.Focused && (state & ColumnState.Hovered) == ColumnState.Hovered)
				{
					using (Brush brush = new LinearGradientBrush(bounds, System.Drawing.Color.FromArgb(64, 96, 144, 240), System.Drawing.Color.FromArgb(196, 96, 144, 240), LinearGradientMode.Vertical))
					{
						g.FillRectangle(brush, bounds);
						goto IL_A7;
					}
				}
				using (Brush brush2 = new LinearGradientBrush(bounds, System.Drawing.Color.FromArgb(32, 128, 128, 128), System.Drawing.Color.FromArgb(196, 128, 128, 128), LinearGradientMode.Vertical))
				{
					g.FillRectangle(brush2, bounds);
				}
				IL_A7:
				using (Brush brush3 = new LinearGradientBrush(bounds, System.Drawing.Color.FromArgb(96, 128, 128, 128), System.Drawing.Color.FromArgb(128, 128, 128), LinearGradientMode.Vertical))
				{
					using (Pen pen = new Pen(brush3))
					{
						g.DrawLine(pen, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom);
						g.DrawLine(pen, bounds.Left, bounds.Bottom - 1, bounds.Right, bounds.Bottom - 1);
					}
				}
				using (Pen pen2 = new Pen(System.Drawing.Color.FromArgb(16, System.Drawing.Color.White)))
				{
					g.DrawLine(pen2, bounds.Left + 1, bounds.Top + 1, bounds.Left + 1, bounds.Bottom - 2);
					g.DrawLine(pen2, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom - 2);
				}
				int num = 4;
				if (this.mImageListView.SortOrder != SortOrder.None && this.mImageListView.SortColumn == column.Type)
				{
					Image image = null;
					if (this.mImageListView.SortOrder == SortOrder.Ascending)
					{
						image = ImageListViewResources.SortAscending;
					}
					else if (this.mImageListView.SortOrder == SortOrder.Descending)
					{
						image = ImageListViewResources.SortDescending;
					}
					g.DrawImageUnscaled(image, bounds.X + 4, bounds.Top + (bounds.Height - image.Height) / 2);
					num += image.Width;
				}
				bounds.X += num;
				bounds.Width -= num;
				if (bounds.Width > 4)
				{
					using (StringFormat stringFormat = new StringFormat())
					{
						stringFormat.FormatFlags = StringFormatFlags.NoWrap;
						stringFormat.Alignment = StringAlignment.Near;
						stringFormat.LineAlignment = StringAlignment.Center;
						stringFormat.Trimming = StringTrimming.EllipsisCharacter;
						using (Brush brush4 = new SolidBrush(System.Drawing.Color.White))
						{
							g.DrawString(column.Text, (this.mImageListView.HeaderFont == null) ? this.mImageListView.Font : this.mImageListView.HeaderFont, brush4, bounds, stringFormat);
						}
					}
				}
			}

			public override void DrawColumnExtender(Graphics g, System.Drawing.Rectangle bounds)
			{
				using (Brush brush = new LinearGradientBrush(bounds, System.Drawing.Color.FromArgb(32, 128, 128, 128), System.Drawing.Color.FromArgb(196, 128, 128, 128), LinearGradientMode.Vertical))
				{
					g.FillRectangle(brush, bounds);
				}
				using (Brush brush2 = new LinearGradientBrush(bounds, System.Drawing.Color.FromArgb(96, 128, 128, 128), System.Drawing.Color.FromArgb(128, 128, 128), LinearGradientMode.Vertical))
				{
					using (Pen pen = new Pen(brush2))
					{
						g.DrawLine(pen, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom);
						g.DrawLine(pen, bounds.Left, bounds.Bottom - 1, bounds.Right, bounds.Bottom - 1);
					}
				}
				using (Pen pen2 = new Pen(System.Drawing.Color.FromArgb(16, System.Drawing.Color.White)))
				{
					g.DrawLine(pen2, bounds.Left + 1, bounds.Top + 1, bounds.Left + 1, bounds.Bottom - 2);
					g.DrawLine(pen2, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom - 2);
				}
			}

			public override void DrawGalleryImage(Graphics g, ImageListViewItem item, Image image, System.Drawing.Rectangle bounds)
			{
				if (item != null && image != null)
				{
					Size size = this.MeasureItemMargin(base.ImageListView.View);
					System.Drawing.Rectangle sizedImageBounds = Utility.GetSizedImageBounds(image, new System.Drawing.Rectangle(bounds.X + size.Width, bounds.Y + size.Height, bounds.Width - 2 * size.Width, bounds.Height - 2 * size.Height - this.mReflectionSize), 50f, 100f);
					this.DrawImageWithReflection(g, image, sizedImageBounds, this.mReflectionSize);
				}
			}

			public override void DrawPane(Graphics g, ImageListViewItem item, Image image, System.Drawing.Rectangle bounds)
			{
				using (Brush brush = new SolidBrush(System.Drawing.Color.FromArgb(64, 64, 64)))
				{
					g.FillRectangle(brush, bounds.Right - 2, bounds.Top, 2, bounds.Height);
				}
				bounds.Width -= 2;
				if (item != null && image != null)
				{
					Size size = this.MeasureItemMargin(base.ImageListView.View);
					System.Drawing.Rectangle sizedImageBounds = Utility.GetSizedImageBounds(image, new System.Drawing.Rectangle(bounds.Location + size, bounds.Size - size - size), 50f, 0f);
					g.DrawImage(image, sizedImageBounds);
					bounds.X += size.Width;
					bounds.Width -= 2 * size.Width;
					bounds.Y = sizedImageBounds.Height + 16;
					bounds.Height -= sizedImageBounds.Height + 16;
					if (this.mImageListView.Columns[ColumnType.Name].Visible && bounds.Height > 0)
					{
						int num = Utility.DrawStringPair(g, bounds, "", item.Text, this.mImageListView.Font, Brushes.White, Brushes.White);
						bounds.Y += 2 * num;
						bounds.Height -= 2 * num;
					}
					if (this.mImageListView.Columns[ColumnType.FileType].Visible && bounds.Height > 0 && !string.IsNullOrEmpty(item.FileType))
					{
						using (Brush brush2 = new SolidBrush(System.Drawing.Color.FromArgb(196, 196, 196)))
						{
							using (Brush brush3 = new SolidBrush(System.Drawing.Color.White))
							{
								int num2 = Utility.DrawStringPair(g, bounds, this.mImageListView.Columns[ColumnType.FileType].Text + ": ", item.FileType, this.mImageListView.Font, brush2, brush3);
								bounds.Y += num2;
								bounds.Height -= num2;
							}
						}
					}
					foreach (ImageListView.ImageListViewColumnHeader imageListViewColumnHeader in this.mImageListView.Columns)
					{
						if (imageListViewColumnHeader.Type == ColumnType.ImageDescription)
						{
							bounds.Y += 8;
							bounds.Height -= 8;
						}
						if (bounds.Height <= 0)
						{
							break;
						}
						if (imageListViewColumnHeader.Visible && imageListViewColumnHeader.Type != ColumnType.FileType && imageListViewColumnHeader.Type != ColumnType.DateAccessed && imageListViewColumnHeader.Type != ColumnType.FileName && imageListViewColumnHeader.Type != ColumnType.FilePath && imageListViewColumnHeader.Type != ColumnType.Name)
						{
							string text = imageListViewColumnHeader.Text;
							string subItemText = item.GetSubItemText(imageListViewColumnHeader.Type);
							if (!string.IsNullOrEmpty(subItemText))
							{
								using (Brush brush4 = new SolidBrush(System.Drawing.Color.FromArgb(196, 196, 196)))
								{
									using (Brush brush5 = new SolidBrush(System.Drawing.Color.White))
									{
										int num3 = Utility.DrawStringPair(g, bounds, text + ": ", subItemText, this.mImageListView.Font, brush4, brush5);
										bounds.Y += num3;
										bounds.Height -= num3;
									}
								}
							}
						}
					}
				}
			}

			public override void DrawSelectionRectangle(Graphics g, System.Drawing.Rectangle selection)
			{
				using (Brush brush = new LinearGradientBrush(selection, System.Drawing.Color.FromArgb(160, 96, 144, 240), System.Drawing.Color.FromArgb(32, 96, 144, 240), LinearGradientMode.ForwardDiagonal))
				{
					g.FillRectangle(brush, selection);
				}
				using (Brush brush2 = new LinearGradientBrush(selection, System.Drawing.Color.FromArgb(96, 144, 240), System.Drawing.Color.FromArgb(128, 96, 144, 240), LinearGradientMode.ForwardDiagonal))
				{
					using (Pen pen = new Pen(brush2))
					{
						g.DrawRectangle(pen, selection);
					}
				}
			}

			public override void DrawInsertionCaret(Graphics g, System.Drawing.Rectangle bounds)
			{
				using (Brush brush = new SolidBrush(System.Drawing.Color.FromArgb(96, 144, 240)))
				{
					g.FillRectangle(brush, bounds);
				}
			}

			private void DrawImageWithReflection(Graphics g, Image img, int x, int y, int reflection)
			{
				g.DrawImageUnscaled(img, x, y + 1);
				if (img.Width > 32 && img.Height > 32)
				{
					int num = img.Height / 2;
					if (num > reflection)
					{
						num = reflection;
					}
					Region clip = g.Clip;
					g.SetClip(new System.Drawing.Rectangle(x, y + img.Height + 1, img.Width, num));
					g.DrawImage(img, x, y + img.Height + img.Height / 2 + 1, img.Width, -img.Height / 2);
					g.Clip = clip;
					using (Brush brush = new LinearGradientBrush(new System.Drawing.Point(x, y + img.Height + 1), new System.Drawing.Point(x, y + img.Height + num + 1), System.Drawing.Color.FromArgb(128, 16, 16, 16), System.Drawing.Color.FromArgb(16, 16, 16)))
					{
						g.FillRectangle(brush, x, y + img.Height + 1, img.Width, num);
					}
				}
			}

			private void DrawImageWithReflection(Graphics g, Image img, int x, int y, int width, int height, int reflection)
			{
				g.DrawImage(img, x, y + 1, width, height);
				if (img.Width > 32 && img.Height > 32)
				{
					int num = height / 2;
					if (num > reflection)
					{
						num = reflection;
					}
					Region clip = g.Clip;
					g.SetClip(new System.Drawing.Rectangle(x, y + height + 1, width, num));
					g.DrawImage(img, x, y + height + height / 2 + 1, width, -height / 2);
					g.Clip = clip;
					using (Brush brush = new LinearGradientBrush(new System.Drawing.Point(x, y + height + 1), new System.Drawing.Point(x, y + height + num + 1), System.Drawing.Color.FromArgb(128, 16, 16, 16), System.Drawing.Color.FromArgb(16, 16, 16)))
					{
						g.FillRectangle(brush, x, y + height + 1, width, num);
					}
				}
			}

			private void DrawImageWithReflection(Graphics g, Image img, System.Drawing.Rectangle bounds, int reflection)
			{
				this.DrawImageWithReflection(g, img, bounds.X, bounds.Y, bounds.Width, bounds.Height, reflection);
			}

			private int padding;

			private int mReflectionSize;
		}

		public class TilesRenderer : ImageListView.ImageListViewRenderer
		{
			public int TileWidth
			{
				get
				{
					return this.mTileWidth;
				}
				set
				{
					this.mTileWidth = value;
				}
			}

			private Font CaptionFont
			{
				get
				{
					if (this.mCaptionFont == null)
					{
						this.mCaptionFont = new Font(base.ImageListView.Font, FontStyle.Bold);
					}
					return this.mCaptionFont;
				}
			}

			public TilesRenderer() : this(150)
			{
			}

			public TilesRenderer(int tileWidth)
			{
				this.mTileWidth = tileWidth;
			}

			public override void Dispose()
			{
				if (this.mCaptionFont != null)
				{
					this.mCaptionFont.Dispose();
				}
				base.Dispose();
			}

			public override Size MeasureItem(Autodesk.Revit.DB.View view)
			{
				if (view == Autodesk.Revit.DB.View.Thumbnails)
				{
					Size result = default(Size);
					this.mTextHeight = (int)(5.8f * (float)this.CaptionFont.Height);
					Size size = new Size(4, 4);
					result.Width = base.ImageListView.ThumbnailSize.Width + 4 * size.Width + this.mTileWidth;
					result.Height = Math.Max(this.mTextHeight, base.ImageListView.ThumbnailSize.Height) + 2 * size.Height;
					return result;
				}
				return base.MeasureItem(view);
			}

			public override void DrawItem(Graphics g, ImageListViewItem item, ItemState state, System.Drawing.Rectangle bounds)
			{
				if (base.ImageListView.View == Autodesk.Revit.DB.View.Thumbnails)
				{
					Size sz = new Size(4, 4);
					using (Brush brush = new SolidBrush(item.BackColor))
					{
						g.FillRectangle(brush, bounds);
					}
					if ((base.ImageListView.Focused && (state & ItemState.Selected) != ItemState.None) || (!base.ImageListView.Focused && (state & ItemState.Selected) != ItemState.None && (state & ItemState.Hovered) != ItemState.None))
					{
						using (Brush brush2 = new LinearGradientBrush(bounds, System.Drawing.Color.FromArgb(16, SystemColors.Highlight), System.Drawing.Color.FromArgb(64, SystemColors.Highlight), LinearGradientMode.Vertical))
						{
							Utility.FillRoundedRectangle(g, brush2, bounds, 4);
							goto IL_E8;
						}
					}
					if (!base.ImageListView.Focused && (state & ItemState.Selected) != ItemState.None)
					{
						using (Brush brush3 = new LinearGradientBrush(bounds, System.Drawing.Color.FromArgb(16, SystemColors.GrayText), System.Drawing.Color.FromArgb(64, SystemColors.GrayText), LinearGradientMode.Vertical))
						{
							Utility.FillRoundedRectangle(g, brush3, bounds, 4);
						}
					}
					IL_E8:
					if ((state & ItemState.Hovered) != ItemState.None)
					{
						using (Brush brush4 = new LinearGradientBrush(bounds, System.Drawing.Color.FromArgb(8, SystemColors.Highlight), System.Drawing.Color.FromArgb(32, SystemColors.Highlight), LinearGradientMode.Vertical))
						{
							Utility.FillRoundedRectangle(g, brush4, bounds, 4);
						}
					}
					Image thumbnailImage = item.ThumbnailImage;
					if (thumbnailImage != null)
					{
						System.Drawing.Rectangle sizedImageBounds = Utility.GetSizedImageBounds(thumbnailImage, new System.Drawing.Rectangle(bounds.Location + sz, base.ImageListView.ThumbnailSize), 0f, 50f);
						g.DrawImage(thumbnailImage, sizedImageBounds);
						if (Math.Min(sizedImageBounds.Width, sizedImageBounds.Height) > 32)
						{
							using (Pen pen = new Pen(System.Drawing.Color.FromArgb(128, System.Drawing.Color.Gray)))
							{
								g.DrawRectangle(pen, sizedImageBounds);
							}
							using (Pen pen2 = new Pen(System.Drawing.Color.FromArgb(128, System.Drawing.Color.White)))
							{
								g.DrawRectangle(pen2, System.Drawing.Rectangle.Inflate(sizedImageBounds, -1, -1));
							}
						}
						int height = this.CaptionFont.Height;
						using (StringFormat stringFormat = new StringFormat())
						{
							RectangleF layoutRectangle = new RectangleF((float)(bounds.Left + 2 * sz.Width + base.ImageListView.ThumbnailSize.Width), (float)(bounds.Top + sz.Height + (Math.Max(base.ImageListView.ThumbnailSize.Height, this.mTextHeight) - this.mTextHeight) / 2), (float)this.mTileWidth, (float)height);
							stringFormat.Alignment = StringAlignment.Near;
							stringFormat.FormatFlags = StringFormatFlags.NoWrap;
							stringFormat.LineAlignment = StringAlignment.Center;
							stringFormat.Trimming = StringTrimming.EllipsisCharacter;
							using (Brush brush5 = new SolidBrush(item.ForeColor))
							{
								g.DrawString(item.Text, this.CaptionFont, brush5, layoutRectangle, stringFormat);
							}
							using (Brush brush6 = new SolidBrush(System.Drawing.Color.Gray))
							{
								layoutRectangle.Offset(0f, 1.5f * (float)height);
								if (!string.IsNullOrEmpty(item.FileType))
								{
									g.DrawString(item.GetSubItemText(ColumnType.FileType), base.ImageListView.Font, brush6, layoutRectangle, stringFormat);
									layoutRectangle.Offset(0f, 1.1f * (float)height);
								}
								if (item.Dimensions != Size.Empty || item.Resolution != SizeF.Empty)
								{
									string text = "";
									if (item.Dimensions != Size.Empty)
									{
										text = text + item.GetSubItemText(ColumnType.Dimensions) + " pixels ";
									}
									if (item.Resolution != SizeF.Empty)
									{
										text = text + item.Resolution.Width + " dpi";
									}
									g.DrawString(text, base.ImageListView.Font, brush6, layoutRectangle, stringFormat);
									layoutRectangle.Offset(0f, 1.1f * (float)height);
								}
								if (item.FileSize != 0L)
								{
									g.DrawString(item.GetSubItemText(ColumnType.FileSize), base.ImageListView.Font, brush6, layoutRectangle, stringFormat);
									layoutRectangle.Offset(0f, 1.1f * (float)height);
								}
								if (item.DateModified != DateTime.MinValue)
								{
									g.DrawString(item.GetSubItemText(ColumnType.DateModified), base.ImageListView.Font, brush6, layoutRectangle, stringFormat);
								}
							}
						}
					}
					using (Pen pen3 = new Pen(System.Drawing.Color.FromArgb(128, System.Drawing.Color.White)))
					{
						Utility.DrawRoundedRectangle(g, pen3, bounds.Left + 1, bounds.Top + 1, bounds.Width - 3, bounds.Height - 3, 4);
					}
					if (base.ImageListView.Focused && (state & ItemState.Selected) != ItemState.None)
					{
						using (Pen pen4 = new Pen(System.Drawing.Color.FromArgb(128, SystemColors.Highlight)))
						{
							Utility.DrawRoundedRectangle(g, pen4, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
							goto IL_5C0;
						}
					}
					if (!base.ImageListView.Focused && (state & ItemState.Selected) != ItemState.None)
					{
						using (Pen pen5 = new Pen(System.Drawing.Color.FromArgb(128, SystemColors.GrayText)))
						{
							Utility.DrawRoundedRectangle(g, pen5, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
							goto IL_5C0;
						}
					}
					if ((state & ItemState.Selected) == ItemState.None)
					{
						using (Pen pen6 = new Pen(System.Drawing.Color.FromArgb(64, SystemColors.GrayText)))
						{
							Utility.DrawRoundedRectangle(g, pen6, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
						}
					}
					IL_5C0:
					if (base.ImageListView.Focused && (state & ItemState.Hovered) != ItemState.None)
					{
						using (Pen pen7 = new Pen(System.Drawing.Color.FromArgb(64, SystemColors.Highlight)))
						{
							Utility.DrawRoundedRectangle(g, pen7, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
						}
					}
					if (base.ImageListView.Focused && (state & ItemState.Focused) != ItemState.None)
					{
						ControlPaint.DrawFocusRectangle(g, bounds);
						return;
					}
				}
				else
				{
					base.DrawItem(g, item, state, bounds);
				}
			}

			private Font mCaptionFont;

			private int mTileWidth;

			private int mTextHeight;
		}

		public class XPRenderer : ImageListView.ImageListViewRenderer
		{
			public override Size MeasureItem(Autodesk.Revit.DB.View view)
			{
				Size result = default(Size);
				int height = base.ImageListView.Font.Height;
				if (view == Autodesk.Revit.DB.View.Details)
				{
					return base.MeasureItem(view);
				}
				Size sz = new Size(4, 4);
				result = base.ImageListView.ThumbnailSize + sz + sz;
				result.Height += height + Math.Max(4, height / 3) + sz.Height;
				return result;
			}

			public override void DrawItem(Graphics g, ImageListViewItem item, ItemState state, System.Drawing.Rectangle bounds)
			{
				using (Brush brush = new SolidBrush(item.BackColor))
				{
					g.FillRectangle(brush, bounds);
				}
				if (base.ImageListView.View != Autodesk.Revit.DB.View.Details)
				{
					Size sz = new Size(4, 4);
					Image thumbnailImage = item.ThumbnailImage;
					if (thumbnailImage != null)
					{
						System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(bounds.Location + sz, base.ImageListView.ThumbnailSize);
						System.Drawing.Rectangle sizedImageBounds = Utility.GetSizedImageBounds(thumbnailImage, rectangle);
						g.DrawImage(thumbnailImage, sizedImageBounds);
						if (base.ImageListView.Focused && (state & ItemState.Selected) != ItemState.None)
						{
							using (Pen pen = new Pen(SystemColors.Highlight, 3f))
							{
								g.DrawRectangle(pen, rectangle);
								goto IL_125;
							}
						}
						if (!base.ImageListView.Focused && (state & ItemState.Selected) != ItemState.None)
						{
							using (Pen pen2 = new Pen(SystemColors.GrayText, 3f))
							{
								pen2.Alignment = PenAlignment.Center;
								g.DrawRectangle(pen2, rectangle);
								goto IL_125;
							}
						}
						using (Pen pen3 = new Pen(System.Drawing.Color.FromArgb(128, SystemColors.GrayText)))
						{
							g.DrawRectangle(pen3, rectangle);
						}
					}
					IL_125:
					SizeF sizeF = TextRenderer.MeasureText(item.Text, base.ImageListView.Font);
					RectangleF rectangleF;
					using (StringFormat stringFormat = new StringFormat())
					{
						rectangleF = new RectangleF((float)(bounds.Left + sz.Width), (float)(bounds.Top + 3 * sz.Height + base.ImageListView.ThumbnailSize.Height), (float)base.ImageListView.ThumbnailSize.Width, sizeF.Height);
						stringFormat.Alignment = StringAlignment.Center;
						stringFormat.FormatFlags = StringFormatFlags.NoWrap;
						stringFormat.LineAlignment = StringAlignment.Center;
						stringFormat.Trimming = StringTrimming.EllipsisCharacter;
						rectangleF.Width += 1f;
						rectangleF.Inflate(1f, 2f);
						if (base.ImageListView.Focused && (state & ItemState.Focused) != ItemState.None)
						{
							rectangleF.Inflate(-1f, -1f);
						}
						if (base.ImageListView.Focused && (state & ItemState.Selected) != ItemState.None)
						{
							g.FillRectangle(SystemBrushes.Highlight, rectangleF);
						}
						else if (!base.ImageListView.Focused && (state & ItemState.Selected) != ItemState.None)
						{
							g.FillRectangle(SystemBrushes.GrayText, rectangleF);
						}
						if ((state & ItemState.Selected) != ItemState.None)
						{
							g.DrawString(item.Text, base.ImageListView.Font, SystemBrushes.HighlightText, rectangleF, stringFormat);
						}
						else
						{
							using (Brush brush2 = new SolidBrush(item.ForeColor))
							{
								g.DrawString(item.Text, base.ImageListView.Font, brush2, rectangleF, stringFormat);
							}
						}
					}
					if (base.ImageListView.Focused && (state & ItemState.Focused) != ItemState.None)
					{
						System.Drawing.Rectangle rectangle2 = System.Drawing.Rectangle.Round(rectangleF);
						rectangle2.Inflate(1, 1);
						ControlPaint.DrawFocusRectangle(g, rectangle2);
						return;
					}
				}
				else
				{
					if (base.ImageListView.Focused && (state & ItemState.Selected) != ItemState.None)
					{
						g.FillRectangle(SystemBrushes.Highlight, bounds);
					}
					else if (!base.ImageListView.Focused && (state & ItemState.Selected) != ItemState.None)
					{
						g.FillRectangle(SystemBrushes.GrayText, bounds);
					}
					Size size = new Size(2, (bounds.Height - base.ImageListView.Font.Height) / 2);
					using (StringFormat stringFormat2 = new StringFormat())
					{
						stringFormat2.FormatFlags = StringFormatFlags.NoWrap;
						stringFormat2.Alignment = StringAlignment.Near;
						stringFormat2.LineAlignment = StringAlignment.Center;
						stringFormat2.Trimming = StringTrimming.EllipsisCharacter;
						List<ImageListView.ImageListViewColumnHeader> displayedColumns = base.ImageListView.Columns.GetDisplayedColumns();
						RectangleF layoutRectangle = new RectangleF((float)(bounds.Left + size.Width), (float)(bounds.Top + size.Height), (float)(displayedColumns[0].Width - 2 * size.Width), (float)(bounds.Height - 2 * size.Height));
						foreach (ImageListView.ImageListViewColumnHeader imageListViewColumnHeader in displayedColumns)
						{
							layoutRectangle.Width = (float)(imageListViewColumnHeader.Width - 2 * size.Width);
							using (Brush brush3 = new SolidBrush(item.ForeColor))
							{
								if ((state & ItemState.Selected) == ItemState.None)
								{
									g.DrawString(item.GetSubItemText(imageListViewColumnHeader.Type), base.ImageListView.Font, brush3, layoutRectangle, stringFormat2);
								}
								else
								{
									g.DrawString(item.GetSubItemText(imageListViewColumnHeader.Type), base.ImageListView.Font, SystemBrushes.HighlightText, layoutRectangle, stringFormat2);
								}
							}
							layoutRectangle.X += (float)imageListViewColumnHeader.Width;
						}
					}
					if (base.ImageListView.Focused && (state & ItemState.Focused) != ItemState.None)
					{
						ControlPaint.DrawFocusRectangle(g, bounds);
					}
				}
			}

			public override void DrawGalleryImage(Graphics g, ImageListViewItem item, Image image, System.Drawing.Rectangle bounds)
			{
				Size size = this.MeasureItemMargin(this.mImageListView.View);
				System.Drawing.Rectangle sizedImageBounds = Utility.GetSizedImageBounds(image, new System.Drawing.Rectangle(bounds.Location + size, bounds.Size - size - size));
				g.DrawImage(image, sizedImageBounds);
				if (Math.Min(sizedImageBounds.Width, sizedImageBounds.Height) > 32)
				{
					using (Pen pen = new Pen(System.Drawing.Color.Black))
					{
						g.DrawRectangle(pen, sizedImageBounds);
					}
				}
			}
		}

		public class ZoomingRenderer : ImageListView.ImageListViewRenderer
		{
			public float ZoomRatio
			{
				get
				{
					return this.mZoomRatio;
				}
				set
				{
					this.mZoomRatio = value;
					if (this.mZoomRatio < 0f)
					{
						this.mZoomRatio = 0f;
					}
				}
			}

			public ZoomingRenderer() : this(0.5f)
			{
			}

			public ZoomingRenderer(float zoomRatio)
			{
				if (zoomRatio < 0f)
				{
					zoomRatio = 0f;
				}
				this.mZoomRatio = zoomRatio;
			}

			public override void InitializeGraphics(Graphics g)
			{
				base.InitializeGraphics(g);
				base.Clip = false;
				base.ItemDrawOrder = ItemDrawOrder.NormalSelectedHovered;
			}

			public override Size MeasureItem(Autodesk.Revit.DB.View view)
			{
				if (view == Autodesk.Revit.DB.View.Thumbnails)
				{
					return base.ImageListView.ThumbnailSize + new Size(8, 8);
				}
				return base.MeasureItem(view);
			}

			public override void DrawItem(Graphics g, ImageListViewItem item, ItemState state, System.Drawing.Rectangle bounds)
			{
				if (base.ImageListView.View == Autodesk.Revit.DB.View.Thumbnails)
				{
					if ((state & ItemState.Hovered) != ItemState.None)
					{
						bounds.Inflate((int)((float)bounds.Width * this.mZoomRatio), (int)((float)bounds.Height * this.mZoomRatio));
						if (bounds.Bottom > base.ItemAreaBounds.Bottom)
						{
							bounds.Y = base.ItemAreaBounds.Bottom - bounds.Height;
						}
						if (bounds.Top < base.ItemAreaBounds.Top)
						{
							bounds.Y = base.ItemAreaBounds.Top;
						}
						if (bounds.Right > base.ItemAreaBounds.Right)
						{
							bounds.X = base.ItemAreaBounds.Right - bounds.Width;
						}
						if (bounds.Left < base.ItemAreaBounds.Left)
						{
							bounds.X = base.ItemAreaBounds.Left;
						}
					}
					Image image = null;
					if ((state & ItemState.Hovered) != ItemState.None)
					{
						image = base.GetImageAsync(item, new Size(bounds.Width - 8, bounds.Height - 8));
					}
					if (image == null)
					{
						image = item.ThumbnailImage;
					}
					System.Drawing.Rectangle sizedImageBounds = Utility.GetSizedImageBounds(image, System.Drawing.Rectangle.Inflate(bounds, -8, -8));
					int width = sizedImageBounds.Width;
					int height = sizedImageBounds.Height;
					int x = sizedImageBounds.X;
					int num = sizedImageBounds.Y;
					if ((state & ItemState.Hovered) != ItemState.None && (bounds.Height - height) / 2 < base.ImageListView.Font.Height + 8)
					{
						int num2 = base.ImageListView.Font.Height + 8 - (bounds.Height - height) / 2;
						bounds.Height += 2 * num2;
						num += num2;
					}
					using (Brush brush = new SolidBrush(base.ImageListView.BackColor))
					{
						Utility.FillRoundedRectangle(g, brush, bounds, 5);
					}
					using (Brush brush2 = new SolidBrush(item.BackColor))
					{
						Utility.FillRoundedRectangle(g, brush2, bounds, 5);
					}
					if ((state & ItemState.Selected) != ItemState.None)
					{
						using (Brush brush3 = new SolidBrush(SystemColors.Highlight))
						{
							Utility.FillRoundedRectangle(g, brush3, bounds, 5);
							goto IL_291;
						}
					}
					if (!base.ImageListView.Focused && (state & ItemState.Selected) != ItemState.None)
					{
						using (Brush brush4 = new LinearGradientBrush(bounds, System.Drawing.Color.FromArgb(16, SystemColors.GrayText), System.Drawing.Color.FromArgb(64, SystemColors.GrayText), LinearGradientMode.Vertical))
						{
							Utility.FillRoundedRectangle(g, brush4, bounds, 5);
						}
					}
					IL_291:
					if ((state & ItemState.Hovered) != ItemState.None)
					{
						using (Brush brush5 = new LinearGradientBrush(bounds, System.Drawing.Color.FromArgb(8, SystemColors.Highlight), System.Drawing.Color.FromArgb(32, SystemColors.Highlight), LinearGradientMode.Vertical))
						{
							Utility.FillRoundedRectangle(g, brush5, bounds, 5);
						}
					}
					g.DrawImage(image, x, num, width, height);
					if (Math.Min(width, height) > 32)
					{
						using (Pen pen = new Pen(System.Drawing.Color.FromArgb(128, System.Drawing.Color.Gray)))
						{
							g.DrawRectangle(pen, x, num, width, height);
						}
						if (Math.Min(width, height) > 32)
						{
							using (Pen pen2 = new Pen(System.Drawing.Color.FromArgb(128, System.Drawing.Color.White)))
							{
								g.DrawRectangle(pen2, x + 1, num + 1, width - 2, height - 2);
							}
						}
					}
					if ((state & ItemState.Hovered) != ItemState.None)
					{
						using (StringFormat stringFormat = new StringFormat())
						{
							RectangleF layoutRectangle = new RectangleF((float)(bounds.Left + 4), (float)(bounds.Top + 4), (float)(bounds.Width - 8), (float)((bounds.Height - height) / 2 - 8));
							stringFormat.Alignment = StringAlignment.Center;
							stringFormat.FormatFlags = StringFormatFlags.NoWrap;
							stringFormat.LineAlignment = StringAlignment.Center;
							stringFormat.Trimming = StringTrimming.EllipsisCharacter;
							using (Brush brush6 = new SolidBrush(item.ForeColor))
							{
								g.DrawString(item.Text, base.ImageListView.Font, brush6, layoutRectangle, stringFormat);
							}
						}
					}
					using (Pen pen3 = new Pen(System.Drawing.Color.FromArgb(128, System.Drawing.Color.White)))
					{
						Utility.DrawRoundedRectangle(g, pen3, bounds.Left + 1, bounds.Top + 1, bounds.Width - 3, bounds.Height - 3, 4);
					}
					if (base.ImageListView.Focused && (state & ItemState.Selected) != ItemState.None)
					{
						using (Pen pen4 = new Pen(System.Drawing.Color.FromArgb(128, SystemColors.Highlight)))
						{
							Utility.DrawRoundedRectangle(g, pen4, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
							goto IL_56A;
						}
					}
					if (!base.ImageListView.Focused && (state & ItemState.Selected) != ItemState.None)
					{
						using (Pen pen5 = new Pen(System.Drawing.Color.FromArgb(128, SystemColors.GrayText)))
						{
							Utility.DrawRoundedRectangle(g, pen5, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
							goto IL_56A;
						}
					}
					if ((state & ItemState.Selected) == ItemState.None)
					{
						using (Pen pen6 = new Pen(System.Drawing.Color.FromArgb(64, SystemColors.GrayText)))
						{
							Utility.DrawRoundedRectangle(g, pen6, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
						}
					}
					IL_56A:
					if (!base.ImageListView.Focused || (state & ItemState.Hovered) == ItemState.None)
					{
						return;
					}
					using (Pen pen7 = new Pen(System.Drawing.Color.FromArgb(64, SystemColors.Highlight)))
					{
						Utility.DrawRoundedRectangle(g, pen7, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
						return;
					}
				}
				base.DrawItem(g, item, state, bounds);
			}

			private float mZoomRatio;
		}
	}
}
